package services

import (
	"context"
	"gamers/core"
	v1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
	kctx = context.TODO()
)

// GetNamespaceListService: 获取命名空间列表后端逻辑
func GetNamespaceListService() (*v1.NamespaceList, error) {
	datachannel := make(chan *v1.NamespaceList, 1)
	errchan := make(chan error)
	go func() {
		data, err := core.KubeClient.CoreV1().Namespaces().List(kctx, metav1.ListOptions{})
		if err != nil {
			errchan <- err
		}
		datachannel <- data
	}()
	select {
	case data := <-datachannel:
		return data, nil
	case errchan := <-errchan:
		return nil, errchan
	}
}
